#include "network.h"
#include "systemfile.h"

network::network(datebase *db)
{
    this->mydb = db;
}

void network::carIn(QString Vehicle,QString image_name)
{
    /*QString str;
    //("http://192.168.10.78:30/api/v1/in");
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/in");
    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&car_no=").append(Vehicle).append("&in_image=").append(image_name);
    qDebug()<<"in_carin"<<str;
    QUrl url(str);
    QNetworkRequest request(url);
    webInforIn->get(request);*/

    QString str,str_htp;
    //("http://192.168.10.78:30/api/v1/in");
    if(sysInfo->park_type==1)
    {
        str_htp="in";
    }else if(sysInfo->park_type==2)
    {
        str_htp="in_stall";
    }else if(sysInfo->park_type==3)
    {
        str_htp="in_count";
    }else if(sysInfo->park_type==4)
    {
        str_htp="in_stall_count";
    }else{
        str_htp="in";
    }
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/").append(str_htp);
    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&car_no=").append(Vehicle).append("&in_image=").append(image_name);
    qDebug()<<str;
    QUrl url(str);
    QNetworkRequest request(url);
    webInforIn->get(request);
}

void network::carTempIn(QString Vehicle,QString image_name)/////???carTempIn与这个carIn有啥不同
{
    QString str;
    //("http://192.168.10.78:30/api/v1/temp_in");
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/temp_in");
    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&car_no=").append(Vehicle).append("&in_image=").append(image_name);
    qDebug()<<str;
    QUrl url(str);
    QNetworkRequest request(url);
    webInforTempIn->get(request);
}

void network::carOut(QString Vehicle,QString image_name,QString vehicle_flag)
{
    // QString str("http://192.168.10.78:30/api/v1/out");
    /*QString str;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/out");
    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&car_no=").append(Vehicle).append("&out_image=").append(image_name).append("&vehicle_flag=").append(vehicle_flag);
    //str.append("?controller_sn=43017318&car_no=").append(Vehicle);
    QUrl url(str);
    QNetworkRequest request(url);
    webInforOut->get(request);*/
    QString str,str_htp_out;
    if(sysInfo->park_type==1)
    {
        str_htp_out="out";
    }else if(sysInfo->park_type==2)
    {
        str_htp_out="out_stall";
    }else if(sysInfo->park_type==3)
    {
        str_htp_out="out_count";
    }else if(sysInfo->park_type==4)
    {
        str_htp_out="out_stall_count";
    }else{
        str_htp_out="out";
    }
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/").append(str_htp_out);
    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&car_no=").append(Vehicle).append("&out_image=").append(image_name).append("&vehicle_flag=").append(vehicle_flag);
    //str.append("?controller_sn=43017318&car_no=").append(Vehicle);
    qDebug()<<str;
    QUrl url(str);
    QNetworkRequest request(url);
    webInforOut->get(request);
}

QString network::HandCroess(QString Vehicle,QString reason)
{
    QString str;
    str=("controller_sn=");
    str=str.append(sysInfo->galleryNumber).append("&car_no=").append(Vehicle).append("&reason=").append(reason);
    return str;
}

void  network::HandReason()
{
    QString str;
    str=("http://");
    str=str.append(sysInfo->serverIp).append("/api/v1/hand");
    str.append("?controller_sn=").append(sysInfo->galleryNumber);
    QUrl url(str);
    QNetworkRequest request(url);
    webInforReason->get(request);
}

void  network::GetTime()
{
    QString str;
    str=("http://");
    str=str.append(sysInfo->serverIp).append("/api/v1/get_time");
    // str=str.append(sysInfo->serverIp).append("/api/v1/remaining_stall");
    str.append("?controller_sn=").append(sysInfo->galleryNumber);
    QUrl url(str);
    QNetworkRequest request(url);
    webInforTime->get(request);
}

void network::GetRemain()
{
    QString str;
    str=("http://");
    //str=str.append(sysInfo->serverIp).append("/api/v1/get_time");
    str=str.append(sysInfo->serverIp).append("/api/v1/remaining_stall");
    str.append("?controller_sn=").append(sysInfo->galleryNumber);
    QUrl url(str);
    QNetworkRequest request(url);
    webInforRemain->get(request);
}

QString network::down_picture(QString date, QString picname)
{
    //"http://101.227.244.80:6600/car_images/2016-01-05/1.jpg
    QString str;
    str=("http://");
    str=str.append(sysInfo->serverIp).append("/car_images/");
    str.append(date).append("/").append(picname);
    qDebug()<<"down_picture-"<<str;
    return str;
}

void network::FreeCar(ticketCheck_t *checkInfo,QString fact_fee)
{
    /*QString str,met;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/update_fee");
    met=("controller_sn=");
    QString OpenOutdata=met.append(sysInfo->galleryNumber).append("&pass_no=").append(passno);
    QByteArray append=OpenOutdata.toLatin1();
    QUrl url(str);
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentLengthHeader, append.length());
    webInforFree->post(request,append);*/
    QString str,met;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/update_fee");
    met=("controller_sn=");
    QString OpenOutdata=met.append(sysInfo->galleryNumber).append("&pass_no=").append(checkInfo->pass_num).append("&out_time=").append(checkInfo->endTime).append("&parked_time=").append(checkInfo->parked_time).append("&fee=").append(QString::number(checkInfo->money)).append("&fact_fee=").append(fact_fee).append("&out_image=").append(checkInfo->image_name);
    qDebug()<<"FreeCar"<<OpenOutdata;
    QByteArray append=OpenOutdata.toLatin1();
    QUrl url(str);
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentLengthHeader, append.length());
    webInforFree->post(request,append);
}

void network::FirstDownLoadCar()
{
    //http://127.0.0.1:30/api/v1/info_vehicles?updated_at=2015-02-05;
    //    QString str;
    //    //QString CarTime=mydb->select_carTime(&mydb->sqlite_db);
    //    str=("http://");
    //    str=str.append(sysInfo->serverIp).append("/api/v1/first_down_car");
    //    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&id=").append("NULL");

    //    QUrl url(str);
    //    QNetworkRequest request(url);
    //    webFirstCar->get(request);
}

void network::DownLoadCar(QString max_updated_at)
{
    QString str;
    str=("http://");
    str=str.append(sysInfo->serverIp).append("/api/v1/down_info_vehicles");
    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&max_updated_at=").append(max_updated_at);
    QUrl url(str);
    QNetworkRequest request(url);
    webInforCar->get(request);
}

void network::WebPost_HandOut(QString OpenOutdata)
{
    QString str;
    //=("http://192.168.10.78:30/api/v1/hand_open_out");
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/hand_open_out");
    QByteArray append=OpenOutdata.toAscii();
    QUrl url(str);
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentLengthHeader, append.length());
    webInforHandOUT->post(request,append);
}

/*void Producer::run()
{
    QEventLoop loop;
   //QString vechiel="null";
    QString str=cardown(retu_Vehicle);
    QUrl url(str);
    QNetworkRequest request(url);
    QNetworkReply *reply=manager->get(request);
    connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();
    Producer_WebCarMessage(reply);
}

bool Producer::Producer_WebCarMessage(QNetworkReply *reply)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strWebCar"<<str;
        if(str.length()<10)
        {
         //   emit MsgSignal("null");
            return false;
        }
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QScriptValueIterator it(sc);
        while (it.hasNext())
        {
            QString Ref,carNo,Time,status,stop_date,start_date;
            ticketCheck_t MydbCarInfo,check_car;
            /*QString Ref=sc.property("id").toString ();
            QString carNo=sc.property("car_no").toString ();
            QString Time=sc.property("updated_at").toString ();
            QString status=sc.property("status").toString ();*/
/*      it.next();
            if(!it.value().property("id").toString().isEmpty())
            {
                Ref=it.value().property("id").toString();

                MydbCarInfo.car_id=Ref;
            }
            if(!it.value().property("car_no").toString().isEmpty())
            {
                carNo=it.value().property("car_no").toString();
                MydbCarInfo.car_no=carNo;
            }
            if(!it.value().property("updated_at").toString().isEmpty())
            {
                Time=it.value().property("updated_at").toString();
                MydbCarInfo.update_time=Time;
            }
            if(!it.value().property("status").toString().isEmpty())
            {
                status=it.value().property("status").toString();

            }
            if(!it.value().property("stop_date").toString().isEmpty())
            {
                stop_date=it.value().property("stop_date").toString().replace(10,1," ").section('.',0,0);
                MydbCarInfo.endTime=stop_date;
            }
            if(!it.value().property("start_date").toString().isEmpty())
            {
                start_date=it.value().property("start_date").toString().replace(10,1," ").section('.',0,0);
                MydbCarInfo.beginTime=start_date;
            }
            */
/*QString Ref=it.value().property("id").toString();
            QString carNo=it.value().property("car_no").toString ();
            QString Time=it.value().property("updated_at").toString ();
            QString status=it.value().property("status").toString ();*/

/* if(status == "正常")
            {
                bool mes;
                mes=pt_mydb->car_chek(&pt_mydb->sqlite_db,&check_car,QString("0"),carNo);
                if(!mes)
                {
                  pt_mydb->writeSqliteCar(&pt_mydb->sqlite_db,&MydbCarInfo);
                }
                reply->deleteLater();
            }else{
                bool mes;
                mes=pt_mydb->car_chek(&pt_mydb->sqlite_db,&check_car,QString("0"),carNo);
                if(mes)
                {
                    pt_mydb->car_delete(&pt_mydb->sqlite_db,carNo);
                }
                reply->deleteLater();
            }
        //  emit MsgSignal(Ref);
          return true;
        }
    }else{
     //   emit MsgSignal("null");
        return false;
    }
}*/

/*QString  Producer::cardown(QString Vehicle_id)
{
    manager = new QNetworkAccessManager(this);
    QString str;
    str=("http://");
    str=str.append(sysInfo->serverIp).append("/api/v1/info_vehicles");
    str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&id=").append(Vehicle_id);
    return str;
}*/

void network::tempcarimage(QByteArray image,QString file_name)
{
    QString str;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/upload_image");
    QByteArray my_filename=file_name.toAscii();
    QByteArray bydata;
    bydata.append("controller_sn=").append(sysInfo->galleryNumber).append("&file=").append(image).append("&file_name=").append(my_filename);
    QUrl url(str);
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentLengthHeader, bydata.length());
    webTempPut->post(request,bydata);
}
void network::WebPost_HandIn(QString OpenIndata)
{
    QString str;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/hand_open_in");
    QByteArray append=OpenIndata.toAscii();
    //QByteArray append=("controller_sn=43017318&car_no=晋AS001&reason=免费车辆");
    QUrl url(str);
    QNetworkRequest request(url);
    //request.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentLengthHeader, append.length());
    //request.setHeader(QNetworkRequest::ContentTypeHeader,"application/octet-stream");
    webInforHandIN->post(request,append);
}
void network::WebPost_InOutRecord(QString Record,QByteArray flag)
{
    QString str;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/in_out_record_upload");
    QByteArray Myappend=Record.toAscii();
    QByteArray bydata;
    bydata.append("controller_sn=").append(sysInfo->galleryNumber).append("&str=").append(Myappend).append("&status=").append(flag);
    QUrl url(str);
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentLengthHeader, bydata.length());
}
void network::WebPost_InOutRecordupload(web_record_in_out info_record,QByteArray picbase)
{
    //qDebug()<<"---------上传通行记录----------network::WebPost_InOutRecordupload";
    QByteArray PicBate=picbase;
    QString str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/in_out_record_upload");
    QByteArray bydata;
    if(info_record.status=="已出"||info_record.status=="跟出")
    {
        bydata.append("controller_sn=").append(sysInfo->galleryNumber).append("&out_imagename=").append(info_record.out_image).append("&out_imagefile=").append(PicBate);
    }
    else if(info_record.status=="已入")
    {
        bydata.append("controller_sn=").append(sysInfo->galleryNumber).append("&in_imagename=").append(info_record.in_image).append("&in_imagefile=").append(PicBate);
    }
    //qDebug()<<str;
    bydata.append("&str=");
    cJSON *root;
    QByteArray by1,by2,by3,by4,by5,by6,by7,by8,by9,by0,by10,by11,by12,by13,by14,by15;
    char *out,*root_passn,*root_car_type,*root_car_no,*root_in_time,*root_in_door,*root_status,*root_out_time,*root_out_door,*root_park_time,*root_cretime,*root_inimage,*root_outimage;
    char *root_fact_fee,*root_fee,*root_stall_code,*root_dev_id;
    by0=info_record.pass_no.toLocal8Bit();
    root_passn=by0.data();

    by1=info_record.car_type.toLocal8Bit();
    root_car_type=by1.data();

    by2=info_record.car_no.toLocal8Bit();
    root_car_no=by2.data();

    by3=info_record.in_time.toLocal8Bit();
    root_in_time=by3.data();

    by4=info_record.in_operator.toLocal8Bit();
    root_in_door=by4.data();

    by5=(info_record.in_image).toLocal8Bit();
    root_inimage=by5.data();

    by6=info_record.stall_code.toLocal8Bit();
    root_stall_code=by6.data();

    by7=info_record.out_time.toLocal8Bit();
    root_out_time=by7.data();

    by8=info_record.out_operator.toLocal8Bit();
    root_out_door=by8.data();

    by9=(info_record.out_image).toLocal8Bit();
    root_outimage=by9.data();

    by10=info_record.status.toLocal8Bit();
    root_status=by10.data();

    by11=info_record.fee.toLocal8Bit();
    root_fee=by11.data();

    by12=info_record.fact_fee.toLocal8Bit();
    root_fact_fee=by12.data();

    by13=info_record.created_at.toLocal8Bit();
    root_cretime=by13.data();

    by14=info_record.parked_time.toLocal8Bit();
    root_park_time=by14.data();

    by15=sysInfo->galleryNumber.toLocal8Bit();
    root_dev_id=by15.data();
    root=cJSON_CreateObject();
    cJSON_AddStringToObject(root, "pass_no",root_passn);
    cJSON_AddStringToObject(root, "card_type", root_car_type);
    cJSON_AddStringToObject(root, "car_no", root_car_no);
    cJSON_AddStringToObject(root,"in_time",root_in_time);
    cJSON_AddStringToObject(root, "in_operator",root_in_door);//in_operator
    cJSON_AddStringToObject(root, "in_image",root_inimage);
    //stall_code    占用车位号，车位主键
    cJSON_AddStringToObject(root, "stall_code",root_stall_code);
    cJSON_AddStringToObject(root, "out_time", root_out_time);
    cJSON_AddStringToObject(root, "out_operator",root_out_door);//out_operator
    cJSON_AddStringToObject(root, "out_image", root_outimage);//out_image
    cJSON_AddStringToObject(root, "status", root_status);
    cJSON_AddStringToObject(root, "fee", root_fee);
    cJSON_AddStringToObject(root, "fact_fee", root_fact_fee);
    cJSON_AddStringToObject(root, "created_at", root_cretime);
    cJSON_AddStringToObject(root, "parked_time",root_park_time);
    cJSON_AddStringToObject(root, "updated_controller_sn",root_dev_id);

    out=cJSON_Print(root);
    //QString send;
    //send=QString(out);
    bydata.append(out);
    QEventLoop loop;
    QUrl url(str);
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    request.setHeader(QNetworkRequest::ContentLengthHeader, bydata.length());

    QNetworkReply *reply=webInforInOutup->post(request,bydata);
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();
    generalWebInOutup(reply,info_record);
}

void network::WebPost_InOutRecorddownload(QString max_updated_at)
{
    QString str;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/in_out_record_download");
    str=str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&max_updated_at=").append(max_updated_at);
    //qDebug()<<max_updated_at;
    //qDebug()<<"network::WebPost_InOutRecorddownload="<<str;
    QUrl url(str);
    QNetworkRequest request(url);
    webInforInOutdown->get(request);
}
void network::WebPost_carbind_download(QString max_updated_at)
{
    QString str;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/down_record_stall_vehicle");
    str=str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&max_updated_at=").append(max_updated_at);
    //qDebug()<<max_updated_at;
    //qDebug()<<"network::WebPost_carbind_download"<<str;
    QUrl url(str);
    QNetworkRequest request(url);
    webInforcarbind->get(request);
}

void network::WebPost_car_stall_download(QString max_updated_at)
{
    QString str;
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/down_info_stall");
    str=str.append("?controller_sn=").append(sysInfo->galleryNumber).append("&max_updated_at=").append(max_updated_at);
    //qDebug()<<"network::WebPost_car_stall_download="<<str;
    QUrl url(str);
    QNetworkRequest request(url);
    webInforcarstall->get(request);
}

bool network::generalWebIn(QNetworkReply *reply,carMessage *carInfor)
{
    QStringList list;
    QString car_falg,car_mes;
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"WebIn"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strWebIn"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        carInfor->carRef=Ref;
        if(Ref==QString::number(0))
        {
            if(Mes.indexOf(",")>0)
            {
                list=Mes.split(',');
                car_falg=list[0];
                car_mes=list[1];
                carInfor->carFlag= car_falg;
                carInfor->carAuto= car_mes;
            }else{
                carInfor->carFlag= Mes;
                carInfor->carAuto= Mes;
            }
            reply->deleteLater();
            return true;
        }else{
            if(Mes.indexOf(",")>0)
            {
                list=Mes.split(',');
                car_falg=list[0];
                car_mes=list[1];
                carInfor->carFlag= car_falg;
                carInfor->carAuto= car_mes;
            }else{
                carInfor->carFlag= Mes;
                carInfor->carAuto= Mes;
            }
            reply->deleteLater();
            return false;
        }
    }else{
        carInfor->carRef="ERROR";
        carInfor->carAuto.clear();
        return false;
    }
}

bool network::generalWebTime(QNetworkReply *reply,carMessage *carInfor)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"WebTime"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strWebTime"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        if(Ref==QString::number(0))
        {
            carInfor->carRef=Ref;
            carInfor->curTime=Mes;
            reply->deleteLater();
            return true;
        }else{
            carInfor->carRef=Ref;
            carInfor->curTime=Mes;
            reply->deleteLater();
            return false;
        }
    }else{
        return false;
    }
}

bool network::generalWebRemain(QNetworkReply *reply,carMessage *carInfor)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    //qDebug()<<"=======WebRemain"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        if(Ref==QString::number(0))
        {
            carInfor->carRef=Ref;
            carInfor->curTime=Mes;
            reply->deleteLater();
            return true;
        }else{
            carInfor->carRef=Ref;
            carInfor->curTime=Mes;
            reply->deleteLater();
            return false;
        }
    }else{
        return false;
    }
}

bool network::generalWebOut(QNetworkReply *reply,carMessage *carInfor)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"WebOut"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strWebOut"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        QString Fee=sc.property("fee").toString ();
        QString passnum=sc.property("pass_no").toString ();
        QStringList list;
        carInfor->carRef=Ref;
        if(Ref==QString::number(1))
        {
            if(Mes.indexOf(",")>0)
            {
                QString car_flag1,car_auto1;
                list=Mes.split(',');
                car_flag1=list[0];
                car_auto1=list[1];
                carInfor->carFlag= car_flag1;
                carInfor->carAuto= car_auto1;
                carInfor->carFee=QString::number(0);
            }else{
                carInfor->carFlag= Mes;
                carInfor->carAuto= Mes;
                carInfor->carFee=QString::number(0);
            }
            reply->deleteLater();
            return false;
        }else{
            QString car_flag,in_time,out_time,statu_time,car_auto;
            if(Mes.indexOf(",")>0)
            {
                list=Mes.split(',');
                car_flag=list[0];
                in_time=list[1];
                out_time=list[2];
                statu_time=list[3];
                car_auto=list[4];
                carInfor->carFlag= car_flag;
                carInfor->carIntime=in_time.mid(5,11);
                carInfor->carOuttime=out_time.mid(5,11);
                carInfor->parked_time=statu_time;
                QString message=mydb->get_park_time(statu_time.toInt()*60); //计算停车时长
                carInfor->carParktime=message;
                carInfor->carAuto= car_auto;

                qDebug()<<"network::generalWebOut"<<car_flag<<in_time<<out_time<<statu_time<<car_auto;
                qDebug()<<"network::generalWebOut message"<<message;
            }else{
                carInfor->carFlag= Mes;
                carInfor->carAuto= Mes;
            }
            carInfor->carFee=Fee;
            carInfor->pass_no= passnum;
            qDebug()<<"carOut"<<carInfor->carIntime<<carInfor->carOuttime;
            reply->deleteLater();
            return true;
        }
    }else{
        carInfor->carRef="ERROR";
        return false;
    }
}

bool network::generalWebHand(QNetworkReply *reply)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"Hand"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strHand"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QScriptValueIterator it(sc);
        QString list[50],list1[50];
        int num;
        num=0;
        mydb->hand_delete(&mydb->sqlite_db);
        while (it.hasNext())
        {
            qDebug()<<"message";
            it.next();
            if(!it.value().property("id").toString().isEmpty())
            {
                qDebug() << it.value().property("id").toString();
                list[num]=it.value().property("id").toString();
            }
            if(!it.value().property("reason").toString().isEmpty())
            {
                //qDebug() << it.value().property("reason").toString();
                list1[num]=it.value().property("reason").toString();
                num++;
            }
        }
        for(int n=0;n<num;n++)
        {
            mydb->hand_insert(&mydb->sqlite_db,list[n],list1[n]);
        }
        reply->deleteLater();
        return true;
    }else{
        reply->deleteLater();
        return false;
    }
}

bool network::generalWebHandOpen(QNetworkReply *reply,carMessage *carInfor)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"HandOpen"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strHandOpen"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        if(Ref==QString::number(1))
        {
            carInfor->carRef= Ref;
            carInfor->carAuto= Mes;
            reply->deleteLater();
            return false;
        }else{
            carInfor->carRef= Ref;
            carInfor->carAuto= Mes;
            reply->deleteLater();
            return true;
        }
    }
}

bool network::generalWebCarMessage(QNetworkReply *reply,carMessage *carInfor)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"WebCar"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strWebCar"<<str;
        if(str.length()<10)
        {
            carInfor->carRef="null";
            return false;
        }
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QScriptValueIterator it(sc);
        while (it.hasNext())
        {
            //carRef返回值  null   id
            QString Ref,carNo,Time,status,stop_date,start_date;
            ticketCheck_t MydbCarInfo;//,check_car;
            it.next();
            if(!it.value().property("updated_at").toString().isEmpty())
            {
                Ref=it.value().property("updated_at").toString();
                carInfor->carRef=Ref;
                MydbCarInfo.car_id=Ref;
                qDebug()<<"carInfor->carRef"<<carInfor->carRef;
                qDebug()<<"MydbCarInfo.car_id"<<MydbCarInfo.car_id;
            }
            if(!it.value().property("car_no").toString().isEmpty())
            {
                carNo=it.value().property("car_no").toString();
                MydbCarInfo.car_no=carNo;
                qDebug()<<"MydbCarInfo.car_no"<<MydbCarInfo.car_no;
            }
            if(!it.value().property("updated_at").toString().isEmpty())
            {
                Time=it.value().property("updated_at").toString();
                MydbCarInfo.update_time=Time;
                qDebug()<<"MydbCarInfo.update_time"<<MydbCarInfo.update_time;
            }
            if(!it.value().property("status").toString().isEmpty())
            {
                status=it.value().property("status").toString();
                qDebug()<<"status"<<status;

            }
            if(!it.value().property("stop_date").toString().isEmpty())
            {
                stop_date=it.value().property("stop_date").toString().replace(10,1," ").section('.',0,0);
                MydbCarInfo.endTime=stop_date;
                qDebug()<<"MydbCarInfo.endTime"<<MydbCarInfo.endTime;
            }
            if(!it.value().property("start_date").toString().isEmpty())
            {
                start_date=it.value().property("start_date").toString().replace(10,1," ").section('.',0,0);
                MydbCarInfo.beginTime=start_date;
                qDebug()<<"MydbCarInfo.beginTime"<<MydbCarInfo.beginTime;
            }
            if(status == "正常")
            {
                mydb->writeSqliteCar(&mydb->sqlite_db,&MydbCarInfo);

            }
        }
        reply->deleteLater();
        return true;
    }else{
        return false;
    }
}

bool network::generalWebInOut(QNetworkReply *reply,carMessage *carInfor)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"InOut"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        QString statu=sc.property("status").toString ();
        qDebug()<<"strInOut"<<str<<statu;
        carInfor->carVehicle=Mes;
        if(Ref==QString::number(1))
        {
            reply->deleteLater();
            return false;
        }else{
            //mydb->inOut_delete(&mydb->sqlite_db,Mes);
            reply->deleteLater();
            return true;
        }
    }else{
        return false;
    }
}

bool network::generalWebInOutup(QNetworkReply *reply,web_record_in_out info_record)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"network::generalWebInOutup"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"*****up record return *****"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString();
        QString Mes=sc.property("msg").toString();
        QString result=sc.property("result").toString();
        if(Ref==QString::number(1))
        {
            reply->deleteLater();
            return false;
        }else if(Ref==QString::number(0)){
            QString in_image,out_image;
            if(info_record.status=="已出")
            {
                //上传成功，修改上传标志为1
                mydb->update_record_flag(&mydb->sqlite_db_bei,info_record);

                //删除出场图片
                out_image=info_record.out_image;
                QString flag=(out_image.remove("-")).mid(0,8);

                QString CurrPath;
                CurrPath=sysInfo->path+"/"+flag+"/";
                QString filename=CurrPath+info_record.out_image;
                QFile fileout(filename);
                if(fileout.remove())
                {
                    qDebug()<<QString("network::generalWebInOutup delete out picture %1 success :").arg(filename);
                }

            }else{
                if(mydb->update_record_flag(&mydb->sqlite_db_bei,info_record))
                {//修改成功
                    in_image=info_record.in_image;
                    QString flag=(in_image.remove("-")).mid(0,8);
                    //QString flag=QString("20").append(info_record.in_image.mid(3,6));
                    QString CurrPath;
                    CurrPath=sysInfo->path+"/"+flag+"/";
                    QString filename=CurrPath+info_record.in_image;
                    QFile filein(filename);
                    if(filein.remove())
                    {
                        qDebug()<<QString("network::generalWebInOutup delete in picture %1 success :").arg(filename);
                    }
                }
            }
            reply->deleteLater();
            return true;
        }else{

            return false;
        }
    }else{

        return false;
    }
}

bool network::generalWebInOutdown(QNetworkReply *reply,QString lasttime)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"ProWebCar generalWebInOutdown"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
       // qDebug()<<"========ProWebinfo_record down ========="<<str;
        if(str.length()<10)
        {
            return false;
        }
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QScriptValueIterator it(sc.property("result"));
        while (it.hasNext())
        {
            QString pass_no,card_type,car_no,in_time,out_operator,out_image,status,fee,fact_fee,created_at,updated_at,parked_time;
            web_record_in_out webCarInfo;
            it.next();
            if(!it.value().property("pass_no").toString().isEmpty())
            {
                pass_no=it.value().property("pass_no").toString();
                webCarInfo.pass_no=pass_no;
            }
            if(!it.value().property("card_type").toString().isEmpty())
            {
                card_type=it.value().property("card_type").toString();
                webCarInfo.car_type=card_type;
            }
            if(!it.value().property("car_no").toString().isEmpty())
            {
                car_no=it.value().property("car_no").toString();
                webCarInfo.car_no=car_no;
            }
            if(!it.value().property("in_time").toString().isEmpty())
            {
                in_time=it.value().property("in_time").toString();
                webCarInfo.in_time=in_time;
            }
            if(!it.value().property("in_operator").toString().isEmpty())
            {
                webCarInfo.in_operator=it.value().property("in_operator").toString();
            }
            if(!it.value().property("in_image").toString().isEmpty())
            {
                webCarInfo.in_image=it.value().property("in_image").toString();
            }
            if(!it.value().property("stall_code").toString().isEmpty())
            {
                webCarInfo.stall_code=it.value().property("stall_code").toString();//.replace(10,1," ").section('.',0,0);
            }
            if(!it.value().property("out_time").toString().isEmpty())
            {
                webCarInfo.out_time=it.value().property("out_time").toString();//.replace(10,1," ").section('.',0,0);
            }
            if(!it.value().property("out_operator").toString().isEmpty())
            {
                out_operator=it.value().property("out_operator").toString();
            }
            if(!it.value().property("out_image").toString().isEmpty())
            {
                out_image=it.value().property("out_image").toString();
                webCarInfo.out_image=out_image;
            }
            if(!it.value().property("status").toString().isEmpty())
            {
                status=it.value().property("status").toString();
                webCarInfo.status=status;
            }
            if(!it.value().property("fee").toString().isEmpty())
            {
                fee=it.value().property("fee").toString();
                webCarInfo.fee=fee;
            }
            if(!it.value().property("fact_fee").toString().isEmpty())
            {
                fact_fee=it.value().property("fact_fee").toString();
                webCarInfo.fact_fee=fact_fee;
            }
            if(!it.value().property("created_at").toString().isEmpty())
            {
                created_at=it.value().property("created_at").toString();
                webCarInfo.created_at=created_at;
            }
            if(!it.value().property("updated_at").toString().isEmpty())
            {

                updated_at=it.value().property("updated_at").toString();
                webCarInfo.updated_at=updated_at;
            }
            if(!it.value().property("parked_time").toString().isEmpty())
            {
                parked_time=it.value().property("parked_time").toString();
                webCarInfo.parked_time=parked_time;
            }
            webCarInfo.flag=1;
            QString in_images,out_images;
            //1不需要上传，0需要上传
            if(!webCarInfo.pass_no.isEmpty())
            {
                QString status;
                status=mydb->check_pass_no(&mydb->sqlite_db_bei,&webCarInfo);
               // qDebug()<<"generalWebInOutdown:check_pass_no"<<status;
                if(status=="null")
                {
                    if(webCarInfo.status=="已入")
                    {
                       mydb->insert_record_in_out(&mydb->sqlite_db_bei,&webCarInfo);
                    }
                }else{
                    if(status=="已入")
                    {
                       mydb->update_record_in_out(&mydb->sqlite_db_bei,&webCarInfo);
                    }
                    if(status=="已出"|| status=="跟出")
                    {   //删除出场图片
                        out_images=webCarInfo.out_image;
                        QString flag=(out_images.remove("-")).mid(0,8);
                        QString CurrPath;
                        CurrPath=sysInfo->path+"/"+flag+"/";
                        QString filename=CurrPath+webCarInfo.out_image;

                        QFile fileout(filename);
                        if(fileout.remove())
                        {
                            qDebug()<<QString("generalWebInOutdown:remove fileout %1 picture success").arg(filename);
                        }
                        in_images=webCarInfo.in_image;
                        QString flag1=(in_images.remove("-")).mid(0,8);

                        CurrPath=sysInfo->path+"/"+flag1+"/";
                        filename=CurrPath+webCarInfo.in_image;
                        QFile filein(filename);
                        if(filein.remove())
                        {
                            qDebug()<<QString("generalWebInOutdown:remove filein %1 picture success").arg(filename);
                        }
                    }
                }
                if(updated_at > lasttime)
                {//更新时间戳
                    mydb->update_lasttime_record(&mydb->sqlite_db_bei,updated_at);
                }
            }
        }
        return true;
    }else{
        return false;
    }
    reply->deleteLater();
}

bool network::generalWebcarbinddown(QNetworkReply *reply)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"ProWebCar bind down"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        //qDebug()<<"========ProWebCar bind down ========="<<str;
        if(str.length()<10){
            //qDebug()<<"car_bind down reply str.length()<10";
            return false;
        }
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QScriptValueIterator it(sc.property("result"));
        while (it.hasNext())
        {
            QString code,car_no,stall_code,status,begin_date,end_date,created_at,updated_at;

            web_car_bind webCarbind;
            it.next();
            if(!it.value().property("code").toString().isEmpty())
            {
                code=it.value().property("code").toString();
                webCarbind.code=code;
               // qDebug()<<"webCarbind.code"<<webCarbind.code;
            }
            if(!it.value().property("car_no").toString().isEmpty())
            {
                car_no=it.value().property("car_no").toString();
                webCarbind.car_no=car_no;
               // qDebug()<<"webCarbind.car_no"<<webCarbind.car_no;
            }
            if(!it.value().property("stall_code").toString().isEmpty())
            {
                stall_code=it.value().property("stall_code").toString();
                webCarbind.stall_code=stall_code;
              //  qDebug()<<"webCarbind.stall_code"<<webCarbind.stall_code;
            }
            if(!it.value().property("status").toString().isEmpty())
            {
                status=it.value().property("status").toString();
                webCarbind.status=status;
               // qDebug()<<"webCarbind.status"<<webCarbind.status;

            }
            if(!it.value().property("begin_date").toString().isEmpty())
            {
                webCarbind.begin_date=it.value().property("begin_date").toString();//.replace(10,1," ").section('.',0,0);
               // qDebug()<<"webCarInfo.begin_date"<<webCarbind.begin_date;
            }
            if(!it.value().property("end_date").toString().isEmpty())
            {
                webCarbind.end_date=it.value().property("end_date").toString();//.replace(10,1," ").section('.',0,0);
               // qDebug()<<"webCarInfo.end_date"<<webCarbind.end_date;

            }
            if(!it.value().property("created_at").toString().isEmpty())
            {
                created_at=it.value().property("created_at").toString();
                webCarbind.created_at=created_at;
              //  qDebug()<<"webCarInfo.created_at"<<webCarbind.created_at;
            }

            if(!it.value().property("updated_at").toString().isEmpty())
            {
                updated_at=it.value().property("updated_at").toString();
                webCarbind.updated_at=updated_at;
              //  qDebug()<<"webCarInfo.updated_at"<<webCarbind.updated_at;
            }
            if(webCarbind.status=="N")
            {
                mydb->delete_car_bind(&mydb->sqlite_db,webCarbind.car_no,webCarbind.stall_code);
            }
            else if(webCarbind.status=="Y")
            {
              //  qDebug()<<"webCarbind.status==Y";
                bool res=mydb->check_car_bind(&mydb->sqlite_db,&webCarbind);
                if(res)
                {
                    //跟新
                 //   qDebug()<<"update_car_bind";
                    mydb->update_car_bind(&mydb->sqlite_db,&webCarbind);
                }
                else
                {
                  //  qDebug()<<"insert_car_bind";
                    mydb->insert_car_bind(&mydb->sqlite_db,&webCarbind);
                }
            }
            reply->deleteLater();
        }
       // qDebug()<< "no info_car_bind to insert to sqlite";
        return true;
    }else{
        return false;
    }
}

bool network::generalWebcarstalldown(QNetworkReply *reply)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"WebCar stall down"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"========WebCar stall down========="<<str;
        if(str.length()<10){
            qDebug()<<"car_stall down reply str.length()<10";
            return false;
        }
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QScriptValueIterator it(sc.property("result"));
        while (it.hasNext())
        {
            QString area_code,print_code,stall_code,created_at,updated_at,status;

            web_car_stall webCarstall;
            it.next();
            if(!it.value().property("area_code").toString().isEmpty())
            {
                area_code=it.value().property("area_code").toString();
                webCarstall.area_code=area_code;
                qDebug()<<"webCarstall.area_code"<<webCarstall.area_code;
            }
            if(!it.value().property("print_code").toString().isEmpty())
            {
                print_code=it.value().property("print_code").toString();
                webCarstall.print_code=print_code;
                qDebug()<<"webCarstall.print_code"<<webCarstall.print_code;
            }
            if(!it.value().property("stall_code").toString().isEmpty())
            {
                stall_code=it.value().property("stall_code").toString();
                webCarstall.stall_code=stall_code;
                qDebug()<<"webCarstall.in_time"<<webCarstall.stall_code;
            }
            if(!it.value().property("status").toString().isEmpty())
            {
                status=it.value().property("status").toString();
                webCarstall.status=status;
                qDebug()<<"webCarstall.in_time"<<webCarstall.status;
            }
            if(!it.value().property("created_at").toString().isEmpty())
            {
                created_at=it.value().property("created_at").toString();
                webCarstall.created_at=created_at;
                qDebug()<<"webCarstall.created_at"<<webCarstall.created_at;
            }
            if(!it.value().property("updated_at").toString().isEmpty())
            {
                updated_at=it.value().property("updated_at").toString();
                webCarstall.updated_at=updated_at;
                qDebug()<<"webCarstall.updated_at"<<webCarstall.updated_at;
            }
            if(webCarstall.status=="正常")
            {//查找车位表，是否已经存在，不存在插入
                if(!mydb->check_car_stall(&mydb->sqlite_db,&webCarstall))
                {
                    mydb->insert_car_stall(&mydb->sqlite_db,&webCarstall);
                }
                //                else{
                //                    mydb->delete_car_stall(&mydb->sqlite_db,&webCarstall);
                //                    mydb->insert_car_stall(&mydb->sqlite_db,&webCarstall);
                //                }
            }
            else if(webCarstall.status=="作废")
            {//查找车位表，存在删除
                if(mydb->check_car_stall(&mydb->sqlite_db,&webCarstall))
                {
                    mydb->delete_car_stall(&mydb->sqlite_db,&webCarstall);
                }
            }
        }
        reply->deleteLater();
        qDebug()<< "no info_car_stall to insert to sqlite";
        return true;
    }else{

        return false;
    }
}

bool network::generalWebCarFirst(QNetworkReply *reply)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"CarFirst"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strCarFirst"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        if(Ref==QString::number(1))
        {
            reply->deleteLater();
            return false;
        }else{
            reply->deleteLater();
            return true;
        }
    }
}

bool network::generalWebTempImage(QNetworkReply *reply,carMessage *carInfor)
{
    QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant redirectionTargetUrl =reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
    qDebug()<<"TempImage"<<statusCodeV.toString ()<<redirectionTargetUrl.toString ();
    if (reply->error() == QNetworkReply::NoError)
    {
        QTextCodec *codec = QTextCodec::codecForName("UTF-8");
        QString str = codec->toUnicode(reply->readAll());
        qDebug()<<"strTempImage"<<str;
        QScriptEngine engine;
        QScriptValue sc = engine.evaluate("value="+str);
        QString Ref=sc.property("ref").toString ();
        QString Mes=sc.property("msg").toString ();
        carInfor->carRef=Ref;
        carInfor->carVehicle=Mes;
        if(Ref==QString::number(1))
        {
            reply->deleteLater();
            return false;
        }else{
            reply->deleteLater();
            return true;
        }
    }else{
        return false;
    }
}

bool network::uploadFile(QString localPath)
{
    QString str;
    QFile file(localPath);
    if (!file.open(QIODevice::ReadOnly))
    {
        file.close();
        qDebug()<<"no file";
        return false;
    }
    str="http://";
    str=str.append(sysInfo->serverIp).append("/api/v1/upload_image");
    QUrl url(str);
    QString crlf="\r\n";
    qsrand(QDateTime::currentDateTime().toTime_t());
    QString b=QVariant(qrand()).toString()+QVariant(qrand()).toString()+QVariant(qrand()).toString();
    QString boundary="---------------------------"+b;
    QString endBoundary=crlf+"--"+boundary+"--"+crlf;
    QString contentType="multipart/form-data; boundary="+boundary;
    boundary="--"+boundary+crlf;
    QByteArray bond=boundary.toAscii();
    QByteArray send;
    send.append("controller_sn=").append(sysInfo->galleryNumber).append("&file=");
    send.append(bond);
    boundary = crlf + boundary;
    bond = boundary.toAscii();
    send.append(QString("Content-Disposition: form-data; name=\"name\""+crlf).toAscii());
    send.append(QString("Content-Transfer-Encoding: 8bit"+crlf).toAscii());
    send.append(crlf.toAscii());
    send.append(QString("文件名称").toUtf8());
    send.append(bond);
    send.append(QString("Content-Disposition: form-data; name=\"visibility\""+crlf).toAscii());
    send.append(QString("Content-Transfer-Encoding: 8bit"+crlf).toAscii());
    send.append(crlf.toAscii());
    send.append(QString("0").toUtf8());
    send.append(bond);
    send.append(QString("Content-Disposition: form-data; name=\"file\"; filename=\""+localPath+"\""+crlf).toAscii());
    //send.append(QString("Content-Type: "+fileMimes.at(i)+crlf+crlf).toAscii());
    send.append(QString("Content-Transfer-Encoding: 8bit"+crlf).toAscii());
    send.append(crlf.toAscii());
    send.append(file.readAll());
    send.append(endBoundary.toAscii());
    file.close();

    QNetworkRequest req(url);
    req.setHeader(QNetworkRequest::ContentTypeHeader, contentType.toAscii());
    req.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(send.size()).toString());
    QNetworkAccessManager qam;
    qam.post(req,send);
    return true;
}

